﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using GameServer.Managers;

namespace GameServer.Networking.Packets
{
    class PACKET_CHARACTER_INFO : Packet
    {
        public PACKET_CHARACTER_INFO(Virtual_Objects.User.virtualUser User)
        {
            newPacket(25088);
            addBlock(1);
            addBlock("Montana_" + Config.SERVER_ID);
            addBlock(User.SessionID);   // SessionID UDP
            addBlock(User.UserID);      // UserID
            addBlock(User.SessionID);   // SessionIDz UDP
            addBlock(User.Nickname);    // Nickname
            //Clan
            addBlock(User.ClanID);
            addBlock(User.ClanName);
            addBlock(User.ClanRank);
            addBlock(User.ClanRank);
            addBlock(0); // <3
            //END Clan
            addBlock(User.Premium); // Premium Type
            addBlock(0);
            addBlock(-1);
            addBlock(0);
            // Level & Exp
            addBlock(LevelCalculator.getLevelforExp(User.Exp)); // Level for EXP
            addBlock(User.Exp); // Exp
            addBlock(User.Cash); // Unknown
            addBlock(0);
            addBlock(User.Dinar);
            addBlock(User.Kills); // Kills
            addBlock(User.Deaths); // Deaths
            addBlock(0);
            addBlock(0);
            addBlock(0);
            addBlock(0);
            addBlock(0);
            addBlock(User.getSlots());

            // Player Equipment //
            for (int Class = 0; Class < 5; Class++)
            {
                StringBuilder ClassBuilder = new StringBuilder();

                for (int Slot = 0; Slot < 8; Slot++)
                {
                    ClassBuilder.Append(User.Equipment[Class, Slot]);
                    if (Slot != 7) ClassBuilder.Append(",");

                }
                addBlock(ClassBuilder.ToString());
            }
            
            addBlock(User.rebuildWeaponList().ToString().Remove(User.rebuildWeaponList().ToString().Length - 1));

            string CostumeE = User.CostumeE; 
            string CostumeM = User.CostumeM;
            string CostumeS = User.CostumeS;
            string CostumeA = User.CostumeA;
            string CostumeH = User.CostumeH;

            addBlock(CostumeE);
            addBlock(CostumeM);
            addBlock(CostumeS);
            addBlock(CostumeA);
            addBlock(CostumeH);

            // Costume Inventory //
            StringBuilder Costumes = new StringBuilder(); int CostumeCount = 0;
            for (int I = 0; I < 30; I++)
            {
                if (User.Costume[I] != null)
                {
                    CostumeItem _Inv = User.Costume[I];
                    TimeSpan ExpireTime = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(_Inv._StartTime);

                    Costumes.Append(_Inv._Code.ToUpper() + "-3-3-" + _Inv._StartTime + "-0-0,");/*+ ExpireTime.TotalSeconds +*/
                    CostumeCount++;
                }
            }

            for (int I = 0; I < (30 - CostumeCount); I++)
            {
                Costumes.Append("^,");
            }

            addBlock(Costumes.ToString().Remove(Costumes.ToString().Length - 1));

            addBlock("WARROCK");
            addBlock(1); // 0 = No Zombie 1 = All Channel 2 = Only Zombie all above = Fucked
            addBlock(0);
            // works now!

            addBlock("Montana");
        }

        public PACKET_CHARACTER_INFO(int ErrorID)
        {
            newPacket(25088);
            addBlock(ErrorID);
        }
    }
}
